﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;
using DAL;
using System.Collections.Generic;

public partial class Home : System.Web.UI.Page
{
    CHUYENMUCBLL cmBll = new CHUYENMUCBLL();
    BAIVIETBLL bvBll = new BAIVIETBLL();
    THANHVIENBLL tvBll = new THANHVIENBLL();
    COMMENTBLL cmeBll = new COMMENTBLL();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["tenthanhvien"] == null) Response.Redirect("LogIn.aspx");
            showDSChuyenmuc();
            showTinhhinhDiendan();
            showTopbaiviet();
            showTopPoster();
            showTopXem();
        }
    }

    public void showTopXem() {
        string inner = "<ol>";
        List<BAIVIET> listBv = bvBll.getTopNXem(3);
        foreach (BAIVIET bv in listBv)
        {
            inner += "<li><div style=\"width:222px; overflow:hidden;height:45px;line-height:45px;\"><b><a href=\"Baiviet.aspx?mabv=" + bv.mabaiviet + "&tenbv=" + bv.tenbaiviet + "\">[" + bv.xem + "] " + bv.tenbaiviet + "</a></b></div></li>";
        }
        inner += "</ol>";
        div_topxem.InnerHtml = inner;
    }

    public void showTopPoster() {
        string inner = "<ol>";
        List<TOPPOSTER> listPos = bvBll.getTopNPoster(3);
        foreach (TOPPOSTER pos in listPos)
        {
            inner += "<li><div style=\"width:222px; overflow:hidden;height:45px;line-height:45px;\"><b>[" + pos.sobai.ToString() + "] " + pos.tenthanhvien + "</b></div></li>";
        }
        inner += "</ol>";
        div_topposter.InnerHtml = inner;
    }

    public void showTopbaiviet() {
        string inner = "<ol>";
        List<BAIVIET> listBv = bvBll.getTopNBaiviet(3);
        foreach(BAIVIET bv in listBv){
            inner += "<li><div style=\"width:222px; overflow:hidden;height:45px;line-height:45px;\"><b><a href=\"Baiviet.aspx?mabv=" + bv.mabaiviet + "&tenbv=" + bv.tenbaiviet + "\">" + bv.tenbaiviet + "</a></b></div></li>";
        }
        inner += "</ol>";
        div_newbaiviet.InnerHtml = inner;
    }

    public void showDSChuyenmuc(){
        pChuyenmuc.InnerHtml = cmBll.getHTMLForHomePage(); 
    }

    public void showTinhhinhDiendan() {

        label_Menber.Text = OnlineActiveUsers.OnlineUsersInstance.OnlineUsers.UsersCount.ToString();
        lb_tongbaiviet.Text = bvBll.count().ToString();
        lb_tongcomment.Text = cmeBll.count().ToString();
        lb_tongthanhvien.Text = tvBll.count().ToString();
    }
}
